package cn.stylefeng.guns.modular.guide.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.guide.entity.UserGuide;
import cn.stylefeng.guns.modular.guide.model.params.UserGuideParam;
import cn.stylefeng.guns.modular.guide.service.UserGuideService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 用户指南控制器
 *
 * @author liuqiang
 * @Date 2020-02-12 20:50:17
 */
@RestController
@RequestMapping("/userGuide")
public class UserGuideController extends BaseController {

    @Autowired
    private UserGuideService userGuideService;

    /**
     * 新增接口
     *
     * @author liuqiang
     * @Date 2020-02-12
     */
    @PostMapping("/addItem")
    public ResponseData addItem(@RequestBody UserGuideParam userGuideParam) {
        userGuideParam.setId(1);
        this.userGuideService.add(userGuideParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author liuqiang
     * @Date 2020-02-12
     */
    @PostMapping("/editItem")
    public ResponseData editItem(@RequestBody UserGuideParam userGuideParam) {
        userGuideParam.setId(1);
        this.userGuideService.update(userGuideParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author liuqiang
     * @Date 2020-02-12
     */
    @RequestMapping("/delete")
    public ResponseData delete(UserGuideParam userGuideParam) {
        this.userGuideService.delete(userGuideParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author liuqiang
     * @Date 2020-02-12
     */
    @GetMapping("/detail")
    public ResponseData detail(UserGuideParam userGuideParam) {
        userGuideParam.setId(1);
        UserGuide detail = this.userGuideService.getById(userGuideParam.getId());
        if(detail == null){
            detail = new UserGuide();
        }
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author liuqiang
     * @Date 2020-02-12
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(UserGuideParam userGuideParam) {
        return this.userGuideService.findPageBySpec(userGuideParam);
    }

}


